package com.bosssoft.boss_exam_core.common.Timer;

import com.alibaba.druid.util.StringUtils;
import com.bosssoft.boss_exam_db.entity.Exam;
import com.bosssoft.boss_exam_db.service.busines.ExamService;
import lombok.Data;
import lombok.extern.slf4j.Slf4j;

import java.lang.reflect.InvocationTargetException;

/***
 * @Author lys(cherish)
 * @Description 关闭考试线程
 * @Date  2019/2/26
 **/
@Data
@Slf4j
public class CloseExamRunnable implements Runnable{

    //任务
    private Exam exam;

    private ExamService examService;

    public CloseExamRunnable(){

    }

    public CloseExamRunnable(Exam exam,ExamService examService){
        this.exam=exam;
        this.examService =examService;
    }

    /***
     * @Author lys(cherish)
     * @Description 关闭考试
     * @Date  2019/2/26
     * @Param []
     * @return void
     **/
    @Override
    public void run() {
        System.out.println("开始操作了");
        System.out.println(exam);
        if(StringUtils.isEmpty(exam.getId())){
           return;
        }
        try {
            examService.deleteForLogic(exam);
        } catch (NoSuchMethodException|InvocationTargetException|IllegalAccessException e) {
           log.error("【定时关闭考试错误】"+e);
        }
    }
}
